// 记录日志工具
const fs = require('fs');
const path = require('path');

/**
 * 记录访问日志
 * @param {string} log 
 */
function accessLog(log) {
    // 获取access.log地址
    const path = getLogPath('access.log');
    // 创建writeStream
    writeAccessLog(log, path);
}

function getLogPath(fileName) {
    const path = `${__dirname} + '/../../logs/${fileName}`;
    return path;
}

function writeAccessLog(log, path) {
    const writeStream = createWriteStream(path);
    // 写入日志
    writeStream.write(log + '\n');
}

// 创建流
function createWriteStream(path) {
    return fs.createWriteStream(path, { flags: 'a' });
}
module.exports = {
    accessLog
}